const path = require('path')
const webpack = require('webpack')
const url = 'http://117.73.2.76:8081/policyapi'

// 基础路径，发布前修改这里,当前配置打包出来的资源都是相对路径

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: process.env.NODE_ENV === 'production'
    ? '/policymng/'
    : '/',
  lintOnSave: true,
  productionSourceMap: false,
  configureWebpack: {
    name: 'dgov-policy',
    resolve: {
      alias: {
        '@': resolve('src'),
        '_s': resolve('src/styles'),
        '_c': resolve('src/components')
      }
    },
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery"
      })
    ]
  },
  chainWebpack: (config) => {
    //忽略的打包文件
    config.externals({
      'vue': 'Vue',
      'vue-router': 'VueRouter',
      'vuex': 'Vuex',
      'axios': 'axios',
      'element-ui': 'ELEMENT',
    })
    const entry = config.entry('app')
    entry
      .add('babel-polyfill')
      .end()
    entry
      .add('classlist-polyfill')
      .end()
    entry
      .add('@/mock')
      .end()
  },
  devServer: {
    // 反向代理配置
    proxy: {
      '/api': {
        target: url,
        ws: true,
        pathRewrite: {
          '^/api': '/'
        }
      }
    }
  }
}
